using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraEditors;


namespace WindowsApplication1
{
    public partial class Form1 : XtraForm
    {
        public Form1()
        {
            InitializeComponent();

            Damany.Imaging.Common.Mediator.Instance.RegisterHandler<Damany.RemoteImaging.Net.Messages.Portrait>(HandlePortrait);

        }

        public void HandlePortrait(Damany.RemoteImaging.Net.Messages.Portrait portrait)
        {
            var img = portrait.FaceImage.Clone();

            this.galleryControl.RunInUIThread( ()=>
                                                   {
                                                       var group = this.galleryControl.Gallery.Groups[0];
                                                       if (group.Items.Count > 50)
                                                       {
                                                           group.Items.RemoveAt(group.Items.Count-1);
                                                       }

                                                       var item = new GalleryItem();
                                                       item.Image = (Image) img;
                                                       item.Caption = portrait.CaptureTime.ToShortTimeString();
                                                       this.galleryControl.Gallery.Groups[0].Items.Insert(0, item);
                                                   } );

            
        }

    }
}